﻿namespace Arms.Framework.Security.Encryptors
{
    using System;

    public static class PasswordGenerator
    {
        private static Random _rand = new Random();

        /// <summary>
        /// Randomly generates a new password
        /// </summary>
        /// <param name="length">Length of the password</param>
        /// <param name="haveNumber">Determines whether a generated password will include numeric digits</param>
        /// <param name="haveSpecial">Determines whether a generated password will include special characters</param>
        /// <returns></returns>
        public static string Generate(int length, bool haveNumber, bool haveSpecial)
        {
            string upperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
            string lowerCase = "abcdefghijkmnopqrstuvwxyz";
            string specialCase = "~`!@#$%^&*()-_=+{}[]:;,?/";
            string numberCase = "0123456789";

            string allows = upperCase + lowerCase;

            if (haveNumber)
            {
                allows += numberCase;
            }
            if (haveSpecial)
            {
                allows += specialCase;
            }

            string newPassword = "";

            for (int i = 0; i < length; i++)
            {
                newPassword += allows[_rand.Next(allows.Length)];
            }

            return newPassword;
        }
    }
}
